<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
	<div data-type="layout" data-define="fit:true,border:false">
		<div data-define="region:'center',border:false" title="">
			<table id="role_gridRole" data-type="grid" title="#springMessage('roleManage')" style="height: 340px"
				data-define="
				method:'post',url: '${rc.contextPath}/admin/queryRoleForGrid.do',idField:'roleId',
				rownumbers:true, pagination:true, pageSize:30, toolbar: '#tb1_rolemanage',
				onClickRow:startEdit,
				fitColumns:true, fit:true">
				<thead>
					<tr>
						<th data-define="field:'roleId',width:80,checkbox:true">ID</th>
						<!-- 角色名称 -->
						<th data-define="field:'roleName',width:120,editor:{type:'inputbox',options:{required:true}}">#springMessage("roleName")</th>
						<!-- 角色描述 -->
						<th data-define="field:'roleDesc',width:120,editor:{type:'inputbox',options:{required:true}}">#springMessage("roleDesc")</th>
					</tr>
				</thead>
			</table>
		</div>
		<div id="tb1_rolemanage" style="height: auto">
			<a id="role_addButton" href="#" data-type="linkbutton" data-define="iconCls:'icon-add',plain:true">#springMessage("buttonAdd")</a>
			<a id="role_saveButton" href="#" data-type="linkbutton" data-define="iconCls:'icon-save',plain:true">#springMessage("buttonSave")</a>
			<a id="role_delButton" href="#" data-type="linkbutton" data-define="iconCls:'icon-delete',plain:true">#springMessage("buttonDelete")</a>
		</div>
	</div>
	<script type="text/javascript">
        function startEdit(rowIndex) {
            $('#role_gridRole').grid('beginEdit', rowIndex);
        }
        $(document).ready(function() {
            $("#role_addButton").bind("click", function() {
                var index = $('#role_gridRole').grid('getRows').length;
                $('#role_gridRole').grid('insertRow', { 'index' : index, 'row' : {} });
            });
            $("#role_saveButton").bind("click", function() {
                var rows = $('#role_gridRole').grid('getRows');
                for ( var i = 0; i < rows.length; i++) {
                    $('#role_gridRole').grid('endEdit', i);
                    var v = $('#role_gridRole').grid('validateRow', i);
                    if (!v) {
                        showMsg("#springMessage('itemCheckUnSuccess')");
                        return;
                    }
                }
                var url = "${rc.contextPath}/admin/saveRole.do";
                var chanageRows = $('#role_gridRole').grid('getChanges', 'updated');
                $('#role_gridRole').grid('acceptChanges');
                var data = { "roleRows" : JSON.stringify(chanageRows) };
                ajaxPost(url, data, function(rs) {
                    showMsg(rs.msgInfo);
                    $('#role_gridRole').grid("reload");
                });
            });
            $("#role_delButton").bind("click", function() {
                var roleRows = $('#role_gridRole').grid("getChecked");
                if (roleRows == null || roleRows.length == 0) {
                    showMsg("#springMessage('unSelectedMsg')");
                    return;
                } else {
                    roleRows = JSON.stringify(roleRows);
                }
                confirmMsg('#springMessage("confirmDelete")', function(r) {
                    if (r) {
                        var url = '${rc.contextPath}/admin/deleteRoles.do';
                        var data = { "roleRows" : roleRows };
                        ajaxPost(url, data, function(rs) {
                            showMsg(rs.msgInfo);
                            $('#role_gridRole').grid("reload");
                        });
                    }
                });
            });
        });
    </script>
</body>
</html>